home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.1 / perlguts.1 < prev    next >
Text File  |  1995-07-25  |  28KB  |  727 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           perlguts - Perl's Internal Functions
  10.  
  11.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.           This document attempts to describe some of the internal
  13.           functions of the Perl executable.  It is far from complete
  14.           and probably contains many errors.  Please refer any
  15.           questions or comments to the author below.
  16.  
  17.      DDDDaaaattttaaaattttyyyyppppeeeessss
  18.           Perl has three typedefs that handle Perl's three main data
  19.           types:
  20.  
  21.               SV  Scalar Value
  22.               AV  Array Value
  23.               HV  Hash Value
  24.  
  25.           Each typedef has specific routines that manipulate the
  26.           various data type.
  27.  
  28.           WWWWhhhhaaaatttt iiiissss aaaannnn
  29.  
  30.           Perl uses a special typedef IV which is large enough to hold
  31.           either an integer or a pointer.
  32.  
  33.           Perl also uses a special typedef I32 which will always be a
  34.           32-bit integer.
  35.  
  36.           WWWWoooorrrrkkkkiiiinnnngggg wwwwiiiitttthhhh SSSSVVVV''''ssss
  37.  
  38.           An SV can be created and loaded with one command.  There are
  39.           four types of values that can be loaded: an integer value
  40.           (IV), a double (NV), a string, (PV), and another scalar
  41.           (SV).
  42.  
  43.           The four routines are:
  44.  
  45.               SV*  newSViv(IV);
  46.               SV*  newSVnv(double);
  47.               SV*  newSVpv(char*, int);
  48.               SV*  newSVsv(SV*);
  49.  
  50.           To change the value of an *already-existing* scalar, there
  51.           are five routines:
  52.  
  53.               void  sv_setiv(SV*, IV);
  54.               void  sv_setnv(SV*, double);
  55.               void  sv_setpvn(SV*, char*, int)
  56.               void  sv_setpv(SV*, char*);
  57.               void  sv_setsv(SV*, SV*);
  58.  
  59.           Notice that you can choose to specify the length of the
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 6/30/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  71.  
  72.  
  73.  
  74.           string to be assigned by using sv_setpvn, or allow Perl to
  75.           calculate the length by using sv_setpv.  Be warned, though,
  76.           that sv_setpv determines the string's length by using
  77.           strlen, which depends on the string terminating with a NUL
  78.           character.
  79.  
  80.           To access the actual value that an SV points to, you can use
  81.           the macros:
  82.  
  83.               SvIV(SV*)
  84.               SvNV(SV*)
  85.               SvPV(SV*, STRLEN len)
  86.  
  87.           which will automatically coerce the actual scalar type into
  88.           an IV, double, or string.
  89.  
  90.           In the SvPV macro, the length of the string returned is
  91.           placed into the variable len (this is a macro, so you do _n_o_t
  92.           use &len).  If you do not care what the length of the data
  93.           is, use the global variable na.  Remember, however, that
  94.           Perl allows arbitrary strings of data that may both contain
  95.           NUL's and not be terminated by a NUL.
  96.  
  97.           If you simply want to know if the scalar value is TRUE, you
  98.           can use:
  99.  
  100.               SvTRUE(SV*)
  101.  
  102.           Although Perl will automatically grow strings for you, if
  103.           you need to force Perl to allocate more memory for your SV,
  104.           you can use the macro
  105.  
  106.               SvGROW(SV*, STRLEN newlen)
  107.  
  108.           which will determine if more memory needs to be allocated.
  109.           If so, it will call the function sv_grow.  Note that SvGROW
  110.           can only increase, not decrease, the allocated memory of an
  111.           SV.
  112.  
  113.           If you have an SV and want to know what kind of data Perl
  114.           thinks is stored in it, you can use the following macros to
  115.           check the type of SV you have.
  116.  
  117.               SvIOK(SV*)
  118.               SvNOK(SV*)
  119.               SvPOK(SV*)
  120.  
  121.           You can get and set the current length of the string stored
  122.           in an SV with the following macros:
  123.  
  124.               SvCUR(SV*)
  125.               SvCUR_set(SV*, I32 val)
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 6/30/95)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  137.  
  138.  
  139.  
  140.           But note that these are valid only if SvPOK() is true.
  141.  
  142.           If you know the name of a scalar variable, you can get a
  143.           pointer to its SV by using the following:
  144.  
  145.               SV*  perl_get_sv("varname", FALSE);
  146.  
  147.           This returns NULL if the variable does not exist.
  148.  
  149.           If you want to know if this variable (or any other SV) is
  150.           actually defined, you can call:
  151.  
  152.               SvOK(SV*)
  153.  
  154.           The scalar undef value is stored in an SV instance called
  155.           sv_undef.  Its address can be used whenever an SV* is
  156.           needed.
  157.  
  158.           There are also the two values sv_yes and sv_no, which
  159.           contain Boolean TRUE and FALSE values, respectively.  Like
  160.           sv_undef, their addresses can be used whenever an SV* is
  161.           needed.
  162.  
  163.           Do not be fooled into thinking that (SV *) 0 is the same as
  164.           &sv_undef.  Take this code:
  165.  
  166.               SV* sv = (SV*) 0;
  167.               if (I-am-to-return-a-real-value) {
  168.                       sv = sv_2mortal(newSViv(42));
  169.               }
  170.               sv_setsv(ST(0), sv);
  171.  
  172.           This code tries to return a new SV (which contains the value
  173.           42) if it should return a real value, or undef otherwise.
  174.           Instead it has returned a null pointer which, somewhere down
  175.           the line, will cause a segmentation violation, or just weird
  176.           results.  Change the zero to &sv_undef in the first line and
  177.           all will be well.
  178.  
  179.           To free an SV that you've created, call SvREFCNT_dec(SV*).
  180.           Normally this call is not necessary.  See the section on
  181.           MMMMOOOORRRRTTTTAAAALLLLIIIITTTTYYYY.
  182.  
  183.           PPPPrrrriiiivvvvaaaatttteeee aaaannnndddd PPPPuuuubbbblllliiiicccc VVVVaaaalllluuuueeeessss
  184.  
  185.           Recall that the usual method of determining the type of
  186.           scalar you have is to use Sv[INP]OK macros.  Since a scalar
  187.           can be both a number and a string, usually these macros will
  188.           always return TRUE and calling the Sv[INP]V macros will do
  189.           the appropriate conversion of string to integer/double or
  190.           integer/double to string.
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 6/30/95)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  203.  
  204.  
  205.  
  206.           If you _r_e_a_l_l_y need to know if you have an integer, double,
  207.           or string pointer in an SV, you can use the following three
  208.           macros instead:
  209.  
  210.               SvIOKp(SV*)
  211.               SvNOKp(SV*)
  212.               SvPOKp(SV*)
  213.  
  214.           These will tell you if you truly have an integer, double, or
  215.           string pointer stored in your SV.
  216.  
  217.           In general, though, it's best to just use the Sv[INP]V
  218.           macros.
  219.  
  220.           WWWWoooorrrrkkkkiiiinnnngggg wwwwiiiitttthhhh AAAAVVVV''''ssss
  221.  
  222.           There are two ways to create and load an AV.  The first
  223.           method just creates an empty AV:
  224.  
  225.               AV*  newAV();
  226.  
  227.           The second method both creates the AV and initially
  228.           populates it with SV's:
  229.  
  230.               AV*  av_make(I32 num, SV **ptr);
  231.  
  232.           The second argument points to an array containing num SV*'s.
  233.  
  234.           Once the AV has been created, the following operations are
  235.           possible on AV's:
  236.  
  237.               void  av_push(AV*, SV*);
  238.               SV*   av_pop(AV*);
  239.               SV*   av_shift(AV*);
  240.               void  av_unshift(AV*, I32 num);
  241.  
  242.           These should be familiar operations, with the exception of
  243.           av_unshift.  This routine adds num elements at the front of
  244.           the array with the undef value.  You must then use av_store
  245.           (described below) to assign values to these new elements.
  246.  
  247.           Here are some other functions:
  248.  
  249.               I32   av_len(AV*); /* Returns length of array */
  250.  
  251.               SV**  av_fetch(AV*, I32 key, I32 lval);
  252.                       /* Fetches value at key offset, but it seems to
  253.                          set the value to lval if lval is non-zero */
  254.               SV**  av_store(AV*, I32 key, SV* val);
  255.                       /* Stores val at offset key */
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 6/30/95)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  269.  
  270.  
  271.  
  272.               void  av_clear(AV*);
  273.                       /* Clear out all elements, but leave the array */
  274.               void  av_undef(AV*);
  275.                       /* Undefines the array, removing all elements */
  276.  
  277.           If you know the name of an array variable, you can get a
  278.           pointer to its AV by using the following:
  279.  
  280.               AV*  perl_get_av("varname", FALSE);
  281.  
  282.           This returns NULL if the variable does not exist.
  283.  
  284.           WWWWoooorrrrkkkkiiiinnnngggg wwwwiiiitttthhhh HHHHVVVV''''ssss
  285.  
  286.           To create an HV, you use the following routine:
  287.  
  288.               HV*  newHV();
  289.  
  290.           Once the HV has been created, the following operations are
  291.           possible on HV's:
  292.  
  293.               SV**  hv_store(HV*, char* key, U32 klen, SV* val, U32 hash);
  294.               SV**  hv_fetch(HV*, char* key, U32 klen, I32 lval);
  295.  
  296.           The klen parameter is the length of the key being passed in.
  297.           The val argument contains the SV pointer to the scalar being
  298.           stored, and hash is the pre-computed hash value (zero if you
  299.           want hv_store to calculate it for you).  The lval parameter
  300.           indicates whether this fetch is actually a part of a store
  301.           operation.
  302.  
  303.           Remember that hv_store and hv_fetch return SV**'s and not
  304.           just SV*.  In order to access the scalar value, you must
  305.           first dereference the return value.  However, you should
  306.           check to make sure that the return value is not NULL before
  307.           dereferencing it.
  308.  
  309.           These two functions check if a hash table entry exists, and
  310.           deletes it.
  311.  
  312.               bool  hv_exists(HV*, char* key, U32 klen);
  313.               SV*   hv_delete(HV*, char* key, U32 klen);
  314.  
  315.           And more miscellaneous functions:
  316.  
  317.               void   hv_clear(HV*);
  318.                       /* Clears all entries in hash table */
  319.               void   hv_undef(HV*);
  320.                       /* Undefines the hash table */
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.      Page 5                                          (printed 6/30/95)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  335.  
  336.  
  337.  
  338.               I32    hv_iterinit(HV*);
  339.                       /* Prepares starting point to traverse hash table */
  340.               HE*    hv_iternext(HV*);
  341.                       /* Get the next entry, and return a pointer to a
  342.                          structure that has both the key and value */
  343.               char*  hv_iterkey(HE* entry, I32* retlen);
  344.                       /* Get the key from an HE structure and also return
  345.                          the length of the key string */
  346.               SV*     hv_iterval(HV*, HE* entry);
  347.                       /* Return a SV pointer to the value of the HE
  348.                          structure */
  349.  
  350.           If you know the name of a hash variable, you can get a
  351.           pointer to its HV by using the following:
  352.  
  353.               HV*  perl_get_hv("varname", FALSE);
  354.  
  355.           This returns NULL if the variable does not exist.
  356.  
  357.           The hash algorithm, for those who are interested, is:
  358.  
  359.               i = klen;
  360.               hash = 0;
  361.               s = key;
  362.               while (i--)
  363.                   hash = hash * 33 + *s++;
  364.  
  365.  
  366.           RRRReeeeffffeeeerrrreeeennnncccceeeessss
  367.  
  368.           References are a special type of scalar that point to other
  369.           scalar types (including references).  To treat an AV or HV
  370.           as a scalar, it is simply a matter of casting an AV or HV to
  371.           an SV.
  372.  
  373.           To create a reference, use the following command:
  374.  
  375.               SV*  newRV((SV*) pointer);
  376.  
  377.           Once you have a reference, you can use the following macro
  378.           with a cast to the appropriate typedef (SV, AV, HV):
  379.  
  380.               SvRV(SV*)
  381.  
  382.           then call the appropriate routines, casting the returned SV*
  383.           to either an AV* or HV*.
  384.  
  385.           To determine, after dereferencing a reference, if you still
  386.           have a reference, you can use the following macro:
  387.  
  388.               SvROK(SV*)
  389.  
  390.  
  391.  
  392.  
  393.      Page 6                                          (printed 6/30/95)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  401.  
  402.  
  403.  
  404.      XXXXSSSSUUUUBBBB''''SSSS aaaannnndddd tttthhhheeee AAAArrrrgggguuuummmmeeeennnntttt SSSSttttaaaacccckkkk
  405.           The XSUB mechanism is a simple way for Perl programs to
  406.           access C subroutines.  An XSUB routine will have a stack
  407.           that contains the arguments from the Perl program, and a way
  408.           to map from the Perl data structures to a C equivalent.
  409.  
  410.           The stack arguments are accessible through the ST(n) macro,
  411.           which returns the n'th stack argument.  Argument 0 is the
  412.           first argument passed in the Perl subroutine call.  These
  413.           arguments are SV*, and can be used anywhere an SV* is used.
  414.  
  415.           Most of the time, output from the C routine can be handled
  416.           through use of the RETVAL and OUTPUT directives.  However,
  417.           there are some cases where the argument stack is not already
  418.           long enough to handle all the return values.  An example is
  419.           the POSIX _t_z_n_a_m_e() call, which takes no arguments, but
  420.           returns two, the local timezone's standard and summer time
  421.           abbreviations.
  422.  
  423.           To handle this situation, the PPCODE directive is used and
  424.           the stack is extended using the macro:
  425.  
  426.               EXTEND(sp, num);
  427.  
  428.           where sp is the stack pointer, and num is the number of
  429.           elements the stack should be extended by.
  430.  
  431.           Now that there is room on the stack, values can be pushed on
  432.           it using the macros to push IV's, doubles, strings, and SV
  433.           pointers respectively:
  434.  
  435.               PUSHi(IV)
  436.               PUSHn(double)
  437.               PUSHp(char*, I32)
  438.               PUSHs(SV*)
  439.  
  440.           And now the Perl program calling tzname, the two values will
  441.           be assigned as in:
  442.  
  443.               ($standard_abbrev, $summer_abbrev) = POSIX::tzname;
  444.  
  445.           An alternate (and possibly simpler) method to pushing values
  446.           on the stack is to use the macros:
  447.  
  448.               XPUSHi(IV)
  449.               XPUSHn(double)
  450.               XPUSHp(char*, I32)
  451.               XPUSHs(SV*)
  452.  
  453.           These macros automatically adjust the stack for you, if
  454.           needed.
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                                          (printed 6/30/95)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  467.  
  468.  
  469.  
  470.      MMMMoooorrrrttttaaaalllliiiittttyyyy
  471.           In Perl, values are normally "immortal" -- that is, they are
  472.           not freed unless explicitly done so (via the Perl undef call
  473.           or other routines in Perl itself).
  474.  
  475.           In the above example with tzname, we needed to create two
  476.           new SV's to push onto the argument stack, that being the two
  477.           strings.  However, we don't want these new SV's to stick
  478.           around forever because they will eventually be copied into
  479.           the SV's that hold the two scalar variables.
  480.  
  481.           An SV (or AV or HV) that is "mortal" acts in all ways as a
  482.           normal "immortal" SV, AV, or HV, but is only valid in the
  483.           "current context".  When the Perl interpreter leaves the
  484.           current context, the mortal SV, AV, or HV is automatically
  485.           freed.  Generally the "current context" means a single Perl
  486.           statement.
  487.  
  488.           To create a mortal variable, use the functions:
  489.  
  490.               SV*  sv_newmortal()
  491.               SV*  sv_2mortal(SV*)
  492.               SV*  sv_mortalcopy(SV*)
  493.  
  494.           The first call creates a mortal SV, the second converts an
  495.           existing SV to a mortal SV, the third creates a mortal copy
  496.           of an existing SV.
  497.  
  498.           The mortal routines are not just for SV's -- AV's and HV's
  499.           can be made mortal by passing their address (and casting
  500.           them to SV*) to the sv_2mortal or sv_mortalcopy routines.
  501.  
  502.      CCCCrrrreeeeaaaattttiiiinnnngggg NNNNeeeewwww VVVVaaaarrrriiiiaaaabbbblllleeeessss
  503.           To create a new Perl variable, which can be accessed from
  504.           your Perl script, use the following routines, depending on
  505.           the variable type.
  506.  
  507.               SV*  perl_get_sv("varname", TRUE);
  508.               AV*  perl_get_av("varname", TRUE);
  509.               HV*  perl_get_hv("varname", TRUE);
  510.  
  511.           Notice the use of TRUE as the second parameter.  The new
  512.           variable can now be set, using the routines appropriate to
  513.           the data type.
  514.  
  515.      SSSSttttaaaasssshhhheeeessss aaaannnndddd OOOObbbbjjjjeeeeccccttttssss
  516.           A stash is a hash table (associative array) that contains
  517.           all of the different objects that are contained within a
  518.           package.  Each key of the hash table is a symbol name
  519.           (shared by all the different types of objects that have the
  520.           same name), and each value in the hash table is called a GV
  521.           (for Glob Value).  The GV in turn contains references to the
  522.  
  523.  
  524.  
  525.      Page 8                                          (printed 6/30/95)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  533.  
  534.  
  535.  
  536.           various objects of that name, including (but not limited to)
  537.           the following:
  538.  
  539.               Scalar Value
  540.               Array Value
  541.               Hash Value
  542.               File Handle
  543.               Directory Handle
  544.               Format
  545.               Subroutine
  546.  
  547.           Perl stores various stashes in a GV structure (for global
  548.           variable) but represents them with an HV structure.
  549.  
  550.           To get the HV pointer for a particular package, use the
  551.           function:
  552.  
  553.               HV*  gv_stashpv(char* name, I32 create)
  554.               HV*  gv_stashsv(SV*, I32 create)
  555.  
  556.           The first function takes a literal string, the second uses
  557.           the string stored in the SV.
  558.  
  559.           The name that gv_stash*v wants is the name of the package
  560.           whose symbol table you want.  The default package is called
  561.           main.  If you have multiply nested packages, it is legal to
  562.           pass their names to gv_stash*v, separated by :: as in the
  563.           Perl language itself.
  564.  
  565.           Alternately, if you have an SV that is a blessed reference,
  566.           you can find out the stash pointer by using:
  567.  
  568.               HV*  SvSTASH(SvRV(SV*));
  569.  
  570.           then use the following to get the package name itself:
  571.  
  572.               char*  HvNAME(HV* stash);
  573.  
  574.           If you need to return a blessed value to your Perl script,
  575.           you can use the following function:
  576.  
  577.               SV*  sv_bless(SV*, HV* stash)
  578.  
  579.           where the first argument, an SV*, must be a reference, and
  580.           the second argument is a stash.  The returned SV* can now be
  581.           used in the same way as any other SV.
  582.  
  583.      MMMMaaaaggggiiiicccc
  584.           [This section under construction]
  585.  
  586.      DDDDoooouuuubbbblllleeee----TTTTyyyyppppeeeedddd SSSSVVVV''''ssss
  587.           Scalar variables normally contain only one type of value, an
  588.  
  589.  
  590.  
  591.      Page 9                                          (printed 6/30/95)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  599.  
  600.  
  601.  
  602.           integer, double, pointer, or reference.  Perl will
  603.           automatically convert the actual scalar data from the stored
  604.           type into the requested type.
  605.  
  606.           Some scalar variables contain more than one type of scalar
  607.           data.  For example, the variable $! contains either the
  608.           numeric value of errno or its string equivalent from
  609.           sys_errlist[].
  610.  
  611.           To force multiple data values into an SV, you must do two
  612.           things: use the sv_set*v routines to add the additional
  613.           scalar type, then set a flag so that Perl will believe it
  614.           contains more than one type of data.  The four macros to set
  615.           the flags are:
  616.  
  617.                   SvIOK_on
  618.                   SvNOK_on
  619.                   SvPOK_on
  620.                   SvROK_on
  621.  
  622.           The particular macro you must use depends on which sv_set*v
  623.           routine you called first.  This is because every sv_set*v
  624.           routine turns on only the bit for the particular type of
  625.           data being set, and turns off all the rest.
  626.  
  627.           For example, to create a new Perl variable called "dberror"
  628.           that contains both the numeric and descriptive string error
  629.           values, you could use the following code:
  630.  
  631.               extern int  dberror;
  632.               extern char *dberror_list;
  633.  
  634.               SV* sv = perl_get_sv("dberror", TRUE);
  635.               sv_setiv(sv, (IV) dberror);
  636.               sv_setpv(sv, dberror_list[dberror]);
  637.               SvIOK_on(sv);
  638.  
  639.           If the order of sv_setiv and sv_setpv had been reversed,
  640.           then the macro SvPOK_on would need to be called instead of
  641.           SvIOK_on.
  642.  
  643.      CCCCaaaalllllllliiiinnnngggg PPPPeeeerrrrllll RRRRoooouuuuttttiiiinnnneeeessss ffffrrrroooommmm wwwwiiiitttthhhhiiiinnnn CCCC PPPPrrrrooooggggrrrraaaammmmssss
  644.           There are four routines that can be used to call a Perl
  645.           subroutine from within a C program.  These four are:
  646.  
  647.               I32  perl_call_sv(SV*, I32);
  648.               I32  perl_call_pv(char*, I32);
  649.               I32  perl_call_method(char*, I32);
  650.               I32  perl_call_argv(char*, I32, register char**);
  651.  
  652.           The routine most often used should be perl_call_sv.  The SV*
  653.           argument contains either the name of the Perl subroutine to
  654.  
  655.  
  656.  
  657.      Page 10                                         (printed 6/30/95)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLGGGGUUUUTTTTSSSS((((1111))))
  665.  
  666.  
  667.  
  668.           be called, or a reference to the subroutine.  The second
  669.           argument tells the appropriate routine what, if any,
  670.           variables are being returned by the Perl subroutine.
  671.  
  672.           All four routines return the number of arguments that the
  673.           subroutine returned on the Perl stack.
  674.  
  675.           When using these four routines, the programmer must
  676.           manipulate the Perl stack.  These include the following
  677.           macros and functions:
  678.  
  679.               dSP
  680.               PUSHMARK()
  681.               PUTBACK
  682.               SPAGAIN
  683.               ENTER
  684.               SAVETMPS
  685.               FREETMPS
  686.               LEAVE
  687.               XPUSH*()
  688.  
  689.           For more information, consult the _p_e_r_l_c_a_l_l manpage.
  690.  
  691.      MMMMeeeemmmmoooorrrryyyy AAAAllllllllooooccccaaaattttiiiioooonnnn
  692.           [This section under construction]
  693.  
  694.      AAAAUUUUTTTTHHHHOOOORRRR
  695.           Jeff Okamoto <okamoto@corp.hp.com>
  696.  
  697.           With lots of help and suggestions from Dean Roehrich,
  698.           Malcolm Beattie, Andreas Koenig, Paul Hudson, Ilya
  699.           Zakharevich, Paul Marquess, and Neil Bowers.
  700.  
  701.      DDDDAAAATTTTEEEE
  702.           Version 12: 1994/10/16
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.      Page 11                                         (printed 6/30/95)
  724.  
  725.  
  726.  
  727.